﻿using System.Data.SqlClient;

namespace 静态方法
{
    internal class Program
    {
        static void Main(string[] args)
        {

            TestFunc();

            SqlConnection conn = SqlHelper.GetConnection();
            using(conn)
            {
                conn.Open();

                SqlCommand sqlCommand = conn.CreateCommand();
                using(sqlCommand)
                {
                    sqlCommand.CommandText = "select name,age,sex,addr from person ";
                    SqlDataReader reader = sqlCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetString(0));
                    }
                }
            }
            
            Console.WriteLine("Hello, World!");
            Console.ReadKey();
        }


        /// <summary>
        /// 
        /// </summary>
        public static void TestFunc()
        {
            Console.WriteLine("hello world");
        }
    }


    /// <summary>
    /// 静态的工具类
    /// </summary>
    internal static class SqlHelper
    {
        private static readonly string constr = "Data Source=.;Initial Catalog=test;User Id=sa;Password=root123;";


        public static SqlConnection GetConnection()
        {
            return new SqlConnection(constr);
        }



    }
}
